/*
 * 1483. 链表转数组
 * 将一个链表转换为一个数组。
 * https://www.lintcode.com/problem/convert-linked-list-to-array-list/description
 * 
 * 样例
 * 给出链表 1->2->3->null, 返回 [1,2,3].
 * 
 * 2018.06.10 @jeyming
 */
package convert_linked_list_to_array_list_1483;

import java.util.ArrayList;
import java.util.List;

//Definition for ListNode

class ListNode {
	int val;
	ListNode next;
	ListNode(int x) {
		val = x;
		next = null;
	}
}

public class Convert_linked_list_to_array_list_1483 {

	 /**
     * @param head: the head of linked list.
     * @return: An integer list
     */
    public List<Integer> toArrayList(ListNode head) {
        // write your code here
    	List<Integer> list = new ArrayList<Integer>();
    	ListNode p = head;
    	while(p != null) {
    		list.add(p.val);
    		p = p.next;
    	}
    	return list;
    }
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
